package com.itic.mall.system.inter.finance.makeMoneyLog.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.mall.system.inter.finance.makeMoneyLog.persistence.dao.FinanceUserMakeMoneyLogDao;
import com.itic.mall.system.inter.finance.makeMoneyLog.persistence.model.FinanceUserMakeMoneyLog;
import com.itic.mall.system.inter.finance.makeMoneyLog.persistence.model.FinanceUserMakeMoneyLogExample;
import com.itic.mall.system.inter.finance.makeMoneyLog.persistence.model.FinanceUserMakeMoneyLogExample.Criteria;


@Service
@Transactional
public class FinanceUserMakeMoneyLogService
     extends CrudService<FinanceUserMakeMoneyLogDao,FinanceUserMakeMoneyLog,FinanceUserMakeMoneyLogExample> {
    @Autowired
    private FinanceUserMakeMoneyLogDao financeUserMakeMoneyLogDao;

    /**
     * 添加 生钱本金记录
     * @param userId
     * @param money
     * @param orderNo
     * @return
     */
    public String addMakeMoneyLog(String userId,double money,String orderNo) {
    	FinanceUserMakeMoneyLog financeUserMakeMoneyLog = new FinanceUserMakeMoneyLog();
    	financeUserMakeMoneyLog.setIsLiving("1");
    	financeUserMakeMoneyLog.setIsOverDate("0");
    	financeUserMakeMoneyLog.setMoney(money);
    	financeUserMakeMoneyLog.setOrderNo(orderNo);
    	financeUserMakeMoneyLog.setUserId(userId);
    	String result = this.add(financeUserMakeMoneyLog);
    	return result;
    }
    /**
     * 根据userId 和orderNo查询添加
     * @param orderNo
     * @param userId
     * @return
     */
    public FinanceUserMakeMoneyLog getMakeMoneyLogByOrderNo(String orderNo,String userId) {
    	FinanceUserMakeMoneyLogExample financeUserMakeMoneyLogExample = new FinanceUserMakeMoneyLogExample();
    	Criteria criteria = financeUserMakeMoneyLogExample.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andUserIdEqualTo(userId);
    	criteria.andIsLivingEqualTo("1");
    	criteria.andOrderNoEqualTo(orderNo);
    	criteria.andIsOverDateEqualTo("0");
    	List<FinanceUserMakeMoneyLog> financeUserMakeMoneyLogs = this.list(financeUserMakeMoneyLogExample);
    	if(financeUserMakeMoneyLogs.isEmpty())
    		return null;
    	else
    		return financeUserMakeMoneyLogs.get(0);
    }
    
    
    
}